package com.more.offer.algorithm.ali;

/**
 * @author pinoc
 * @date 2021/8/9
 * @description
 */
public class API {

	private long time;

	private int count;

	public long getTime() {
		return time;
	}

	public void setTime(long time) {
		this.time = time;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public boolean isValid(){
		System.out.println(System.currentTimeMillis()/1000);
		// 没有超时
		if(System.currentTimeMillis()/1000 < time){
			if(this.count < 10){
				// 请求小于10次则表示请求成功（为了测试方便没有设为题意的1000）
				this.count ++;
				System.out.println("执行成功");
				return true;
			}else{
				System.out.println("请求超出1000次，失败");
				return false;
			}
		}else{
			// 触发限流则重置
			System.out.println("----------重置----------");
			this.count = 1;
			this.setTime(System.currentTimeMillis()/1000 + 1);
			return true;
		}
	}
}
